

import CommonAction from './common';

export default class  extends CommonAction{
    constructor(comp) {
        super();
        this.comp = comp;
    }


    // 展示查看合同弹窗
    showViewContactModal = async (selectRows) => {
        const {
            props: {
                dispatch,
                emp
            },
            action
        } = this.comp;

        selectRows = action.rowAct.getSelectedRows(selectRows);

        if(!selectRows) {
            return;
        }
        let res = await this.getViewContractData(selectRows);

        if(res.success) {
            dispatch({
                type: 'emp/update',
                payload: {
                    viewContractModalVisible: true,
                    viewContractTableInfo: res.data.columInfo,
                    viewContractTableData: res.data.columData
                }
            });
        }
        
    }

    // 获取查看合同数据
    getViewContractData = async (selectRows) => {
        const {
            props: {
                dispatch,
                emp
            }
        } = this.comp;

        let postData = {
            billids: [],
            pk_org: emp.orgValue.refpk
        };

        selectRows.map((item) => {
            postData.billids.push(item.values['pk_partmng'].value);
        });

        let res = await dispatch({
            type: 'emp/getViewContractData',
            payload: {
                postData: postData
            }
        });

        return res;
    }

    // 生成查看合同的表格信息
    processTableInfo = (resData = []) => {
        let result = resData.map((item) => {
            return {
                ...item,
                title: item.name,
                dataIndex: item.code,
                key: item.code
            }
        });

        return result;
    }
    
    // 生成查看合同表格数据
    processTableData = (resData) => {
        return resData;
    }
}